<h1 class="crayons-title mb-3">Podcasts</h1>

<%= form_tag(admin_podcasts_path, method: "get") do %>
  <div class="inline-flex">
    <%= text_field_tag(:search, params[:search], aria: { label: "Search" }, class: "crayons-textfield", autocomplete: "off") %>
    <%= submit_tag("Search", class: "crayons-btn ml-2") %>
  </div>
<% end %>

<%= paginate @podcasts %>

<table class="crayons-table" width="100%">
  <thead>
    <tr>
      <th scope="col">ID</th>
      <th scope="col">Title</th>
      <th scope="col">Feed URL</th>
      <th scope="col">Eps</th>
      <th scope="col">Reach</th>
      <th scope="col">Pub</th>
      <th scope="col">Status Notice</th>
      <th scope="col">Owners</th>
    </tr>
  </thead>
  <tbody class="crayons-card">
    <% @podcasts.each do |podcast| %>
      <tr>
        <td class="whitespace-nowrap"><%= podcast.id %></td>
        <td><%= link_to podcast.title, edit_admin_podcast_path(podcast) %></td>
        <td><%= link_to podcast.feed_url, podcast.feed_url %></td>
        <td><%= podcast.episodes_count %></td>
        <td><%= podcast.reachable %></td>
        <td><%= podcast.published %></td>
        <td><%= podcast.status_notice %></td>
        <td>
          <% podcast.owners.select(:username).each do |user| %>
+            <p><%= link_to "@#{user.username}", user_url(user), target: "_blank", rel: :noopener %></p>
          <% end %>
        </td>
      </tr>
    <% end %>
  </tbody>
</table>

<%= paginate @podcasts %>
